package com.alstudio.utils.android.sharedpreferences;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class ALSharedPreferencesManager {

	private static SharedPreferences getDefaultSharedPreferences(final Context context){
		SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
		return settings;
	}
	
	/********************************************* 以下为保存方法 ***************************************************/
	public static void updateStringValue(final Context context,final String key, final String vaule) {
		SharedPreferences settings = getDefaultSharedPreferences(context);
		settings.edit().putString(key, vaule).commit();
	}

	public static void updateBooleanValue(final Context context,final String key, final boolean vaule) {
		SharedPreferences settings = getDefaultSharedPreferences(context);
		settings.edit().putBoolean(key, vaule).commit();
	}

	public static void updateIntValue(final Context context,final String key, final int vaule) {
		SharedPreferences settings = getDefaultSharedPreferences(context);
		settings.edit().putInt(key, vaule).commit();

	}

	public static void updateLongValue(final Context context,final String key, final long vaule) {
		SharedPreferences settings = getDefaultSharedPreferences(context);
		settings.edit().putLong(key, vaule).commit();

	}

	public static void updateFloatValue(final Context context,final String key, final float vaule) {
		SharedPreferences settings = getDefaultSharedPreferences(context);
		settings.edit().putFloat(key, vaule).commit();
	}

	/********************************************* 以下为读取方法 ***************************************************/
	public static String getStringVaule(final Context context,final String key,final String defValue) {
		SharedPreferences settings = getDefaultSharedPreferences(context);
		return settings.getString(key, defValue);
	}

	public static boolean getBooleanValue(final Context context,final String key,final boolean defValue) {
		SharedPreferences settings = getDefaultSharedPreferences(context);
		return settings.getBoolean(key, defValue);
	}

	public static int getIntValue(final Context context,final String key,final int defValue) {
		SharedPreferences settings = getDefaultSharedPreferences(context);
		return settings.getInt(key, defValue);
	}

	public static long getLongValue(final Context context,final String key,final long defValue) {
		SharedPreferences settings = getDefaultSharedPreferences(context);
		return settings.getLong(key, defValue);
	}

	public static float getFloatValue(final Context context,final String key,final float defValue) {
		SharedPreferences settings = getDefaultSharedPreferences(context);
		return settings.getFloat(key, defValue);
	}
	
	public static void registerOnSharedPreferenceChangeListener (SharedPreferences.OnSharedPreferenceChangeListener listener){
		
	}
	
	public static void unregisterOnSharedPreferenceChangeListener (SharedPreferences.OnSharedPreferenceChangeListener listener){
		
	}

}
